package com.kangyi.admin.controller;

import com.kangyi.admin.service.ActivitiesSignupService;
import com.kangyi.admin.service.PublicActivityService;
import com.kangyi.dto.ActivitiesSignupPageQueryDTO;
import com.kangyi.dto.BatchProcessingDTO;
import com.kangyi.result.ActivitiesSignupPageResult;
import com.kangyi.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@RestController
@RequestMapping("/admin/signup")
@Api(tags = "超级管理员-公益活动报名审核相关接口")
@Slf4j
public class ActivitiesSignupController {

    @Autowired
    private ActivitiesSignupService activitiesSignupService;

    @GetMapping("/page")
    @ApiOperation("公益活动报名分页查询")
    public Result<ActivitiesSignupPageResult> pageQuery(ActivitiesSignupPageQueryDTO activitiesSignupPageQueryDTO){
        log.info("公益活动报名分页查询:{}", activitiesSignupPageQueryDTO);
        try {
            ActivitiesSignupPageResult activitiesSignupPageResult = activitiesSignupService.pageQuery(activitiesSignupPageQueryDTO);
            return Result.success(activitiesSignupPageResult,"查询成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @DeleteMapping("/delete")
    @ApiOperation("批量删除活动报名审核")
    @CacheEvict(cacheNames = "activity_", allEntries = true)
    public Result deleteActivitySignup(@RequestParam List<Integer> ids){
        log.info("批量删除活动报名审核:{}",ids);
        try {
            activitiesSignupService.deleteActivitySignup(ids);
            return Result.success("删除成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PutMapping("/processing")
    @ApiOperation("批量处理通过/拒绝")
    @CacheEvict(cacheNames = "activity_", allEntries = true)
    public Result batchProcessing(@RequestBody BatchProcessingDTO batchProcessingDTO){
        log.info("批量处理通过/拒绝:{}",batchProcessingDTO);
        try {
            activitiesSignupService.batchProcessing(batchProcessingDTO);
            return Result.success("操作成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
